package com.itheima.dianming.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.dianming.mapper.SignLogMapper;
import com.itheima.dianming.mapper.StuMapper;
import com.itheima.dianming.pojo.domain.Stu;
import com.itheima.dianming.service.SignLogService;
import com.itheima.dianming.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StuServiceImpl
        extends ServiceImpl<StuMapper, Stu> implements StuService {

    @Autowired
    private StuMapper stuMapper;

    @Override
    public Map statics() {
        Map result = new HashMap();
        //统计工作年限占比数据
        List<Map> workTime = stuMapper.staticsByWorkTime();
        result.put("workTime",workTime);
        //统计学历
        List<Map>  education = stuMapper.staticsByEducation();
        result.put("education",education);
        //统计薪资人数
        List<Map>  salaries = stuMapper.staticsBySalary();
        List<String> salaryList = new ArrayList<>();
        List<Long> salaryCount = new ArrayList<>();
        for (Map salary : salaries) {
            salaryList.add((String) salary.get("salary"));
            salaryCount.add((Long) salary.get("value"));
        }
        result.put("salaryList",salaryList);
        result.put("salaryCount",salaryCount);
        //统计薪资散点图

        LambdaQueryWrapper<Stu> qw = new LambdaQueryWrapper<>();
        qw.orderByAsc(Stu::getGroupNumber).orderByAsc(Stu::getExpectSalary);
        qw.ne(Stu::getUsername,"admin");
        List<Stu> stus = stuMapper.selectList(qw);
        List<Map> salaryAll = new ArrayList<>();
        Integer groupNumber = 1;
        Map temp = new HashMap();
        temp.put("symbolSize",20);
        temp.put("type","scatter");
        temp.put("data",new ArrayList<Integer[]>());
        int count=0;
        for (Stu stu : stus) {
            count++;
            if(stu.getGroupNumber() == groupNumber){
                Integer expectSalary = stu.getExpectSalary();
                ArrayList<Integer[]> data = (ArrayList<Integer[]>) temp.get("data");
                data.add(new Integer[]{count,expectSalary});
            }else {
                groupNumber++;
                salaryAll.add(temp);
                temp = new HashMap();
                temp.put("symbolSize",20+groupNumber);
                temp.put("type","scatter");
                temp.put("data",new ArrayList<Integer[]>());
            }
        }
        salaryAll.add(temp);
        result.put("salaryAll",salaryAll);

        Long aLong = stuMapper.avgSalary();
        result.put("avgSalary",aLong);
        return result;
    }
}
